<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
      <el-form-item label="捐赠人姓名" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="捐赠人性别" prop="sex">
        <el-radio v-model="ruleForm.sex" label=0>男</el-radio>
        <el-radio v-model="ruleForm.sex" label=1>女</el-radio>
      </el-form-item>
      <el-form-item label="捐赠人政治面貌" prop="face">
        <el-input v-model="ruleForm.face"></el-input>
      </el-form-item>
      <el-form-item label="工作单位" prop="work">
        <el-input v-model="ruleForm.work"></el-input>
      </el-form-item>
      <el-form-item label="职务" prop="duty">
        <el-input v-model="ruleForm.duty"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="ruleForm.phone"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="ruleForm.email"></el-input>
      </el-form-item>
      <el-form-item label="股票代码" prop="shareNum">
        <el-input v-model="ruleForm.shareNum"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="other">
        <el-input type="textarea" v-model="ruleForm.other"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name:"AddGoodPeople",
    data() {
      return {
        ruleForm: {
          name: '',
          sex: -1,
          face: '',
          work: '',
          duty: '',
          phone: '',
          email: '',
          shareNum: '',
          other: '',
        },
        rules: {
          name: [
            {required: true, message: '不能为空', trigger: 'blur'},
            {min: 2, max: 30, message: '长度在 2 到 30 个字符', trigger: 'blur'}
          ],
          sex: [
            //{required: true, message: '不能为空', trigger: 'blur'},
          ],
          face: [
            {required: true, message: '不能为空', trigger: 'blur'},
          ],
          work: [
            {required: true, message: '不能为空', trigger: 'blur'},
          ],
          duty: [
            {required: true, message: '不能为空', trigger: 'blur'},
          ],
          phone: [
            {required: true, message: '不能为空', trigger: 'blur'},
          ],
          email: [
            {required: true, message: '不能为空', trigger: 'blur'},
          ],
          shareNum: [
            //{ required: true, message: '不能为空', trigger: 'blur' },
          ],
          other: [
            //{ required: true, message: '不能为空', trigger: 'blur' },
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        console.log(formName)
        this.$refs[formName].validate((valid) => {
          if (valid && this.ruleForm.sex != -1) {
            let _this = this
            this.$post({
              url: "goodpeople/create",
              data: _this.ruleForm
            }).then(res => {
              alert('提交成功!即将跳转到捐赠人列表');
              this.$router.push({path: 'goodPeople'});
            })
          } else {
            alert('提交失败!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>
  .avatar-uploader {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #409EFF;
    border-radius: 6px;
    cursor: pointer;
    position: absolute;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    border: 1px dashed #409EFF;
    width: 178px;
    height: 178px;
    display: block;
  }

</style>
